import http from '@/utils/http'
import type { ISlide } from '@/types'

//新增
export const slideAdd = (payload: ISlide) => {
    return http.post('/api/manage/slide', payload)
}
//修改
export const slideEdit = (payload: ISlide) => {
    return http.put(`/api/manage/slide`, payload)
}
//新增或修改
export const slideEditOrAdd = (payload: ISlide) => {
    if (payload.id) {
        return slideEdit(payload)
    } else {
        return slideAdd(payload)
    }
}
//删除
export const slideDel = (id: number) => {
    return http.delete(`/api/manage/slide/${id}`)
}
//查询
export const slideList = () => {
    return http.get('/api/manage/slide')
}
//根据id查询一个
export const slideById = (id: number) => {
    return http.get(`/api/manage/slide/${id}`)
}

export const slideBatchDel = (delIds: number[]) => {
    const delTasks: Promise<ISlide>[] = delIds.map(id => http.delete(`/api/manage/slide/${id}`))
    return Promise.all(delTasks)
}